package com.tuoren.forward.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tuoren.forward.entity.Region;
import com.tuoren.forward.entity.req.IdReq;
import com.tuoren.forward.service.RegionService;
import com.tuoren.forward.util.ResultData;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("region")
@Tag(name= "地区接口")
public class RegionController {

	@Autowired
	RegionService regionService;
	
	@PostMapping("listByPCode")
    @ResponseBody
    @Operation(summary = "列出次级地区")
	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
	public ResultData<List<Region>> listByPCode(@RequestBody IdReq req){
		log.info("listByPCode>>:{}",req);
		return regionService.listByPCode(req.getId());
	}
	
	@PostMapping("getByCode")
    @ResponseBody
    @Operation(summary = "根据编码查地区")
	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
	public ResultData<Region> getByCode(@RequestBody IdReq req){
		log.info("getByCode>>:{}",req);
		return regionService.getByCode(req.getId());
	}
}
